package com.molin.networkTest.socketTest.tcpTest.demo3;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket socket=new ServerSocket(8888);

        while (true) {
            Socket accept = socket.accept();
            //网络流，读到内存
            BufferedInputStream bi=new BufferedInputStream(accept.getInputStream());
            //内存到磁盘
            String dir="D:\\IdeaProjects\\BasicCode\\mIdeaTest\\src\\com\\molin\\networkTest\\socketTest\\tcpTest\\demo3\\";
            String filename= UUID.randomUUID().toString().replace("-","");
            String path=dir+filename+".jpg";
            BufferedOutputStream bo=new BufferedOutputStream(new FileOutputStream(path));

            int b;
            while ((b=bi.read())!=-1){
                bo.write(b);
            }

            bo.close();
            bi.close();
        }
//        socket.close();
    }
}
